

class AppleCake(object):
    def __init__(self,taste="苹果味"):
        self.taste = taste

class OrangeCake(object):
    def __init__(self,taste="橘子味"):
        self.taste = taste

class NoneCake(object):
    def __init__(self,taste="没有这种味道"):
        self.taste = taste

class CakeFactory(object):
    def createCake(self,taste):
        if taste == "橘子":
            cake = OrangeCake()
        elif taste == "苹果":
            cake = AppleCake()
        else:
            cake = NoneCake()
        return cake


class CakeStore(object):
    def __init__(self):
        self.factory = CakeFactory()
    def taste(self,taste):
        cake = self.factory.createCake(taste)
        print("------品尝味道:%s ----"%cake.taste)



class CarStore(object):

    #仅仅定义方法，并没有实现
    def createCar(self,typeName):
        pass
    def order(self,typeName):
        self.car = self.createCar(typeName)

class Test(object):
    def __init__(self):
        self.num = 100
        print("------init-----")
        print(self)
    def __new__(cls):
        print("-----new-------")
        print(cls)
        return object.__new__(cls)
    #def __str__(self):
    #    return "xxxxxx"
#单例模式
class Singlenton(object):
    __instance = None
    __first_init = False

    def __new__(cls,age,name):
        if not cls.__instance:
            cls.__instance = object.__new__(cls)
        return cls.__instance

    def __init__(self,age,name):
        if not self.__first_init:
            self.age = age
            self.name = name
            Singlenton.__first_init = True
        
a = Singlenton(18,"dongge")

b = Singlenton(8,"dongge")
            
print(id(a))
print(id(b))

print(a.age)
print(b.age)

a.age = 19

print(b.age)